/** 
*@Project: UIBase
*@File: BaseApp.java
*@Author: linlin.zou
*@Date: 2014-12-3 
*@Copyright: 2014 www.boshtc.com Inc. All rights reserved.


*/ 
package com.alipear.appbase;

import android.app.Activity;
import android.app.Application;
import android.view.LayoutInflater;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class BaseApp extends Application{
    final List<Activity> activityList = new ArrayList<Activity>();
    static BaseApp self = null;

    @Override
    public void onCreate() {
        super.onCreate();
        self = this;
    }

    public void addActivity(Activity paramActivity) {
        activityList.add(paramActivity);
    }

    public void exit() {
        Iterator<Activity> loderIterator = this.activityList.iterator();
        while (true) {
            if (!loderIterator.hasNext()) {
                System.exit(0);
                return;
            }
            loderIterator.next().finish();

        }
    }

    public void removeActivity(Activity paramActivity) {
        activityList.remove(paramActivity);
    }

    public Activity topActivity() {
       if (activityList.size() > 0) {
           return activityList.get(activityList.size() -1);
       }
       return null;
    }


    @Override
    public void onTerminate() {
        super.onTerminate();
        exit();
    }



    public static LayoutInflater getLayoutInflater() {
        return LayoutInflater.from(getCurApp().getApplicationContext());
    }

    public static BaseApp getCurApp() {
        return self;
    }

    public HashMap<String, Object> getGlobalParams() {
        return globalParams;
    }

    public void setGlobalParams(HashMap<String, Object> globalParams) {
        this.globalParams = globalParams;
    }

    private HashMap<String, Object> globalParams = new HashMap<>();

}
